#!/bin/bash
BASH=/bin/bash

line=$(tail -n 2 /etc/sysconfig/network |head -n 1)
hostname=${line##*=}
echo "$HOSTNAME"

/usr/local/sbin/php-fpm stop
sleep 2
service mysql restart
sleep 3

CMD="
mysql -uroot -paaaa1111 <<EOF
use emross_sanguo_utf8
show tables;
EOF
"
tablename=` sh -c "$CMD"`

for i  in $tablename;
do mysql -uroot -paaaa1111 <<EOF
use emross_sanguo_utf8
optimize table $i;
EOF
done

CMD="
mysql -uroot -paaaa1111 <<EOF
use sanguo_utf8
show tables;
EOF
"
tablename=` sh -c "$CMD"`

for i  in $tablename;
do mysql -uroot -paaaa1111 <<EOF
use sanguo_utf8
optimize table $i;
EOF
done
sleep 2
echo " "
/usr/local/sbin/php-fpm start

echo ""
echo "##########  optimize  Mysql table witch $HOSTNAME successful ###########"
